class myEmitter {
    constructor() {
        this.handler = {}
    }
    on(name, fn) {
        if (!this.handler[name]) {
            this.handler[name] = []
        }
        this.handler[name].push(fn)
    }
    emit(name, ...arg) {
        for (let i = 0; i < this.handler[name].length; i++) {
            this.handler[name][i](...arg)
        }
    }
}

const emitter = new myEmitter()

emitter.on('myEvent', (eventId, time) => {
    console.log(`事件${eventId} 时间：${time} `)
})
let i = 0
setInterval(() => {
    emitter.emit('myEvent', i++, new Date().toLocaleString())
}, 2000);